<!DOCTYPE html>
<html lang="en">
<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
<head>
    <meta charset="UTF-8">
    <title>会议管理</title>
    <link rel="stylesheet" href="css/layui.css" media="all">
    <link rel="stylesheet" href="css/doc.css" media="all">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <style>
    </style>
</head>

<body>
<div class="kit-doc">
    <blockquote class="layui-elem-quote">会议管理</blockquote>
    <table class="layui-table">
        <colgroup>
            <col width="1">
            <col width="150">
            <col width="250">
            <col width="1">
        </colgroup>
        <thead>
            <tr>
                <th>会议id</th>
                <th>会议地址</th>
                <th>会议提醒</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <#if !mettings.records[0]??>
                <button type="button" class="btn btn-primary addMetting" data-toggle="modal" data-target="#addModal">添加</button>
            </#if>
            <#list mettings.records as metting>
                <tr>
                    <td>${metting.id}</td>
                    <td>${metting.address}</td>
                    <td>${metting.remind}</td>
                    <td>
                        <@security.authorize access="hasRole('ADMIN')">
                            <button type="button" class="btn btn-primary addMetting" data-toggle="modal" data-target="#addModal">添加</button>
                            <button type="button" class="btn btn-warning modifyMetting" data-toggle="modal" data-target="#modifyModal">修改</button>
                            <button type="button" class="btn btn-danger deleteMetting">删除</button>
                        </@security.authorize>
                    </td>
                </tr>
            </#list>
        </tbody>
    </table>
</div>
<div id="demo" style="margin-left: 470px;"></div><#--分页条-->
<#--添加会议-->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">添加会议</h4>
            </div>
            <form method="post" action="/addMetting">
                <input type="hidden" name="pageNo" value="${mettings.current}"/>
                <div class="modal-body">
                    <div class="input-group">
                        <label for="recipient-pass" class="control-label">会议地址:</label>
                        <textarea class="form-control" rows="3" cols="70" name="address"></textarea>
                    </div>
                    <div style="width: 1px; height: 10px"></div>
                    <div class="input-group">
                        <label for="recipient-pass" class="control-label">提醒内容:</label>
                        <textarea class="form-control" rows="3" cols="70" name="remind"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">添加</button>
                </div>
            </form>
        </div>
    </div>
</div>
<#--修改会议信息-->
<div class="modal fade" id="modifyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">修改会议信息</h4>
            </div>
            <form method="post" action="/modifyMetting">
                <input type="hidden" name="pageNo" value="${mettings.current}"/>
                <input type="hidden" name="id" class="modifyMettingId"/><#--本条会议id-->
                <div class="modal-body">
                    <div class="input-group">
                        <label for="recipient-pass" class="control-label">会议地址:</label>
                        <textarea class="form-control modifyMettingAddress" rows="3" cols="70" name="address"></textarea>
                    </div>
                    <div style="width: 1px; height: 10px"></div>
                    <div class="input-group">
                        <label for="recipient-pass" class="control-label">提醒内容:</label>
                        <textarea class="form-control modifyMettingRemind" rows="3" cols="70" name="remind"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">修改</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="js/jquery-3.5.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/layui.all.js"></script>
<script type = "text/javascript">
    /**
     * 删除会议
     */
    $('.deleteMetting').click(function() {
        let mettingId = $(this).parents("tr").find("td").eq(0).text();
        if (window.confirm("确认删除这个会议吗?")) {
            //删除考勤
            $.ajax({
                url: URL() + "deleteMetting?",
                type: "DELETE",
                data: "id=" + mettingId,
                success: function() {
                    window.location.href = URL() + "listMetting?pageNo=" + ${mettings.current};
                }
            });
        }
    });

    /**
     * 修改会议信息的回显
     */
    $('.modifyMetting').click(function() {
        let mettingId = $(this).parents("tr").find("td").eq(0).text();
        let address = $(this).parents("tr").find("td").eq(1).text(); //会议地址
        let remind = $(this).parents("tr").find("td").eq(2).text(); //会议提醒
        $('.modifyMettingId').val(mettingId);
        $('.modifyMettingAddress').val(address);
        $('.modifyMettingRemind').val(remind);
    });

    /**
     * 分页
     */
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
        laypage.render({
            elem: 'demo'
            , theme: '#009688'
            , curr: ${mettings.current}// 当前第几页
            , count: ${mettings.total}// 总条数
            , limit: ${mettings.size}// 每页显示的条数
            , jump: function(obj, first) {//obj.curr,当前第几页
                if (!first) {
                    window.location.href = URL() + "listUserWorkStatus?pageNo=" + obj.curr;
                }
            }
        });
    });
    //获取项目路径
    function URL() {
        return window.location.protocol + "//" + window.location.host + "/";
    }
</script>
</body>
</html>